<?php
/**
* @desc 注册用户表单处理
* @author kevin.wang
* @date 2015-01-01 12:00:00
**/
class ArticleForm extends BaseForm
{
	public $name;
	public $sort;
	public $is_show;
	public $content;
	//表单规则
	public function rules()
	{
		return array(
			array('name, sort, is_show, content', 'required', 'message'=>'必填字段不能为空'),
			array('name', 'unique' , 'on'=>'add', 'className'=>'Article', 'message'=>'文章名已存在'),
			array('is_show', 'boolean', 'message'=>'用户状态为布尔值'),
		);
	}
	//写入数据
	public function saveData(){
		$model = new Article;
		$userInfo = json_decode(Yii::app()->session['userinfo'], true);
		$data = $this->attributes;
		$data['author'] = $userInfo['username'];
		$data['content'] = htmlspecialchars($data['content']);
		return $model->insertArticle($data);
	}
	//修改数据
	public function editData($id){
		$model = new Article;
		$data = $this->attributes;
		$data['content'] = htmlspecialchars($data['content']);
		return $model->editArticle($id, $data);
	}
}
